From 83d66b6f735a38e4d05651c8bfb57663a269bc11 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Fri, 13 Jun 2014 23:29:35 +0000 Subject: [PATCH] fondle unicsv header detection some more. this seems like a step backwards, but we cover another error and provide a test case. --- gpsbabel/reference/headerdetection.unicsv | 6 ++++++ gpsbabel/testo.d/unicsv.test | 4 ++++ gpsbabel/unicsv.cc | 20 ++++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 gpsbabel/reference/headerdetection.unicsv diff --git a/gpsbabel/reference/headerdetection.unicsv b/gpsbabel/reference/headerdetection.unicsv new file mode 100644 index 000000000..110c4fc8a --- /dev/null +++ b/gpsbabel/reference/headerdetection.unicsv @@ -0,0 +1,6 @@ +name lat lon ele Ft depth temp heart caden +Lickskillet 40.075297 -105.414373 7526.2467191601 20 60 85 +Gold Hill 40.063311 -105.409614 8248.031496063 18 160 45 +Barker Reservoir Dam 39.966120 -105.482821 8198.8188976378 37 50 +Barker Reservoir Shore 39.962905 -105.502236 8198.8188976378 0 40 +James Peak 39.852048 -105.690364 13330.0524934383 0 70 diff --git a/gpsbabel/testo.d/unicsv.test b/gpsbabel/testo.d/unicsv.test index 0e17f66a5..f84aae274 100644 --- a/gpsbabel/testo.d/unicsv.test +++ b/gpsbabel/testo.d/unicsv.test @@ -14,3 +14,7 @@ compare ${REFERENCE}/garmin_txt-uni.csv ${TMPDIR}/garmin_txt-uni.csv gpsbabel -i gpx -f ${REFERENCE}/gc/GC7FA4.gpx -o unicsv,utc=0 -F ${TMPDIR}/gcunicsv-1.csv gpsbabel -i unicsv,utc=0 -f ${REFERENCE}/gc/GC7FA4~unicsv.csv -o unicsv,utc=0 -F ${TMPDIR}/gcunicsv-2.csv compare ${TMPDIR}/gcunicsv-1.csv ${TMPDIR}/gcunicsv-2.csv + +# check header detection features +gpsbabel -i unicsv,utc=0 -f ${REFERENCE}/headerdetection.unicsv -x transform,trk=wpt -o gpx,garminextensions -F ${TMPDIR}/headerdetection~unicsv.gpx +compare ${TMPDIR}/headerdetection~unicsv.gpx ${REFERENCE}/extensiondata~unicsv.gpx diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 238e398c6..2a63ff890 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -519,11 +519,12 @@ unicsv_compare_fields(const QString& s, const field_t* f) static void -unicsv_fondle_header(char* ibuf) +unicsv_fondle_header(const char* ibuf) { // TODO: clean up this back and forth between QString and char*. - QString s; + QString s = QString(ibuf); char* buf = NULL; + char* cbuf_start = NULL; int column; const cet_cs_vec_t* ascii = &cet_cs_vec_ansi_x3_4_1968; /* us-ascii */ @@ -531,7 +532,6 @@ unicsv_fondle_header(char* ibuf) * If we see a tab in that header, we decree it to be tabsep. */ unicsv_fieldsep = ","; - s = QString(ibuf); // main has set the codec to UTF-8. if (s.contains('\t')) { unicsv_fieldsep = "\t"; } else if (s.contains(';')) { @@ -539,21 +539,22 @@ unicsv_fondle_header(char* ibuf) } else if (s.contains('|')) { unicsv_fieldsep = "|"; } - s = s.toLower(); + cbuf_start = xstrdup(CSTR(s.toLower())); + const char* cbuf = cbuf_start; /* convert the header line into native ascii */ if (global_opts.charset != ascii) { - buf = cet_str_any_to_any(CSTR(s), global_opts.charset, ascii); // CSTR goes back to UTF-8. - ibuf = buf; + buf = cet_str_any_to_any(cbuf, global_opts.charset, ascii); + cbuf = buf; } column = -1; - while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0)) , !s.isEmpty()) { + while ((s = csv_lineparse(cbuf, unicsv_fieldsep, "\"", 0)) , !s.isEmpty()) { s = s.trimmed(); field_t* f = &fields_def[0]; - ibuf = NULL; + cbuf = NULL; column++; unicsv_fields_tab_ct++; @@ -594,6 +595,9 @@ unicsv_fondle_header(char* ibuf) if (buf) { xfree(buf); } + if (cbuf_start) { + xfree(cbuf_start); + } } static void -- 2.30.2